﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Objects;

namespace MINERP.DAL.InfoConfig
{
    public class ProductDAL:DALBase
    {
        private static ObjectQuery<Tb_Product> GetProducts()
        {
            return DataEntites.Tb_Product.Include("paperFace").Include("paperType").Include("Tb_PorductCategory").Include("tb_CostType").Include("tb_ProductType").Where("it.Status <> 0");
        }
        /// <summary>
        /// Get Product list
        /// </summary>
        /// <returns></returns>
        public static List<Tb_Product> GetProductList()
        {
            List<Tb_Product> list = new List<Tb_Product>();
            foreach (Tb_Product product in GetProducts())
            {
                list.Add(product);
            }
            return list;
        }

        /// <summary>
        /// Get Product object
        /// </summary>
        /// <param name="ProductId"></param>
        /// <returns></returns>
        public static Tb_Product GetProductObj(int ProductId)
        {
            return DataEntites.Tb_Product.Include("Tb_FlowTemplate").First(p =>p.ProuctId == ProductId);
        }

        public static Tb_Product GetProductObj(string ProductName)
        {
            return DataEntites.Tb_Product.Include("Tb_FlowTemplate").FirstOrDefault(p => p.ProductName == ProductName);
        }
        /// <summary>
        /// Add product
        /// </summary>
        /// <param name="obj"></param>
        public static void AddProduct(Tb_Product obj)
        {
            DataEntites.AddToTb_Product(obj);
            DataEntites.SaveChanges();
        }
        public static  void AddProductPrintName(Tb_Product obj,string inName)
        {
            ProductPrint pp=new ProductPrint();
            pp.Tb_Product = obj;
            pp.Productid = obj.ProuctId;
            pp.PrintSizeName = inName;
            DataEntites.AddToProductPrint(pp);
            DataEntites.SaveChanges();
        }

        /// <summary>
        /// Update product
        /// </summary>
        /// <param name="obj"></param>
        public static void UpdateProduct(Tb_Product obj)
        {
            DataEntites.SaveChanges();
        }

        /// <summary>
        /// Update product
        /// </summary>
        /// <param name="obj"></param>
        public static void UpdateProduct(Tb_Product obj,ProductPrint inPP)
        {
            DataEntites.AddToProductPrint(inPP);
            DataEntites.SaveChanges();
        }
        /// <summary>
        /// Delete Product
        /// </summary>
        /// <param name="obj"></param>
        public static void DeleteProduct()
        {
            DataEntites.SaveChanges();
        }
    }
}
